package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.YearDept;
import com.aidex.biz.service.YearDeptService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 年报管理Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-01-22
 */
@RestController
@RequestMapping("/biz/bizYearDept")
public class YearDeptController extends BaseController
{
    @Autowired
    private YearDeptService yearDeptService;

    /**
     * 查询年报管理列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizYearDept:list')")
    @GetMapping("/list")
    public R<PageInfo> list(YearDept yearDept, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                yearDept.setCompanyId(null);
        }else{
                     yearDept.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        yearDept.setPage(new PageDomain(request, response));
        return R.data(yearDeptService.findPage(yearDept));
    }

    /**
     * 获取年报管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizYearDept:query')")
    @GetMapping(value = "/{id}")
    public R<YearDept> detail(@PathVariable("id") String id)
    {
        return R.data(yearDeptService.get(id));
    }

    /**
     * 新增年报管理
     */
    @PreAuthorize("@ss.hasPermi('biz:bizYearDept:add')")
    @Log(title = "年报管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  YearDept yearDept)
    {
        return R.status(yearDeptService.batchSave(yearDept));
    }

    /**
     * 修改年报管理
     */
    @PreAuthorize("@ss.hasPermi('biz:bizYearDept:edit')")
    @Log(title = "年报管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated YearDept yearDept)
    {
        return R.status(yearDeptService.save(yearDept));
    }


    /**
     * 删除年报管理
     */
    @PreAuthorize("@ss.hasPermi('biz:bizYearDept:remove')")
    @Log(title = "年报管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(yearDeptService.deleteYearDeptByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizYearDept:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(yearDeptService.findMaxSort(new YearDept()));
    }

    /**
     * 导出年报管理列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizYearDept:export')")
    @Log(title = "年报管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(YearDept yearDept)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    yearDept.setCompanyId(null);
            }else{
                         yearDept.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<YearDept> list = yearDeptService.findList(yearDept);
        ExcelUtil<YearDept> util = new ExcelUtil<YearDept>(YearDept.class);
        return util.exportExcel(list, "年报管理数据");
    }

}
